{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial for the molecular crystal module in PyXtal\n",
    "\n",
    "Source code: https://github.com/qzhu2017/PyXtal\n",
    "\n",
    "Created by Qiang Zhu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.1 Generate a random crystal\n",
    "\n",
    "To use the code, just import the following module\n",
    "```python\n",
    "from pyxtal.molecular_crystal import molecular_crystal\n",
    "```\n",
    "\n",
    "from pyxtal.molecular_crystal import molecular_crystal\n",
    "Ideally, one just needs to define the following parameters:\n",
    "- space group: integer number from 1 to 230\n",
    "- molecules: a list of molecules, e.g. ['H2O']\n",
    "- number of molecules: a list of numbers, e.g. [4]\n",
    "\n",
    "More details can be found at the following [link](https://pyxtal.readthedocs.io/en/latest/pyxtal.molecular_crystal.html#pyxtal.molecular_crystal.molecular_crystal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------Random Molecular Crystal------\n",
      "Dimension: 3\n",
      "Group: P212121\n",
      "Volume factor: 1.1\n",
      "orthorhombic lattice:   7.0438   6.4489   3.8352  90.0000  90.0000  90.0000\n",
      "Wyckoff sites:\n",
      "\tH2O1 @ [0.4849 0.0305 0.9839]  WP:  4a, Site symmetry 1 ==> Euler: 60.430 63.598 20.885\n"
     ]
    }
   ],
   "source": [
    "from pyxtal.molecular_crystal import molecular_crystal\n",
    "\n",
    "h2o = molecular_crystal(19, ['H2O'], [4])\n",
    "print(h2o)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_1600988498903948\"  style=\"position: relative; width: 600px; height: 300px\">\n        <p id=\"3dmolwarning_1600988498903948\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n      resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n}\n\nvar viewer_1600988498903948 = null;\nvar warn = document.getElementById(\"3dmolwarning_1600988498903948\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_1600988498903948 = $3Dmol.createViewer($(\"#3dmolviewer_1600988498903948\"),{backgroundColor:\"white\"});\n\tviewer_1600988498903948.addModel(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P212121'\\n_symmetry_Int_Tables_number                   19\\n_symmetry_cell_setting              orthorhombic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n2 '-x+1/2, -y, z+1/2'\\n3 '-x, y+1/2, -z+1/2'\\n4 'x+1/2, -y+1/2, -z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\n#END\\n\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n\tviewer_1600988498903948.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n\tviewer_1600988498903948.addUnitCell();\n\tviewer_1600988498903948.replicateUnitCell(1,1,1);\n\tviewer_1600988498903948.zoomTo();\nviewer_1600988498903948.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_1600988498903948\"  style=\"position: relative; width: 600px; height: 300px\">\n",
       "        <p id=\"3dmolwarning_1600988498903948\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "      resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n",
       "}\n",
       "\n",
       "var viewer_1600988498903948 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_1600988498903948\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_1600988498903948 = $3Dmol.createViewer($(\"#3dmolviewer_1600988498903948\"),{backgroundColor:\"white\"});\n",
       "\tviewer_1600988498903948.addModel(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P212121'\\n_symmetry_Int_Tables_number                   19\\n_symmetry_cell_setting              orthorhombic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n2 '-x+1/2, -y, z+1/2'\\n3 '-x, y+1/2, -z+1/2'\\n4 'x+1/2, -y+1/2, -z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\n#END\\n\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n",
       "\tviewer_1600988498903948.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n",
       "\tviewer_1600988498903948.addUnitCell();\n",
       "\tviewer_1600988498903948.replicateUnitCell(1,1,1);\n",
       "\tviewer_1600988498903948.zoomTo();\n",
       "viewer_1600988498903948.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<py3Dmol.view at 0x7ff60460eb10>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#display the structure\n",
    "h2o.show()\n",
    "\n",
    "#The crystal can also be exported to pymatgen or ase structure.\n",
    "#pmg_struc = h2o.to_pymatgen()\n",
    "#ase_struc = h2o.to_ase()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_16009884989238489\"  style=\"position: relative; width: 400px; height: 300px\">\n        <p id=\"3dmolwarning_16009884989238489\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n      resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n}\n\nvar viewer_16009884989238489 = null;\nvar warn = document.getElementById(\"3dmolwarning_16009884989238489\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_16009884989238489 = $3Dmol.createViewer($(\"#3dmolviewer_16009884989238489\"),{backgroundColor:\"white\"});\n\tviewer_16009884989238489.addModelsAsFrames(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\nO           0.516309    0.522667    0.527334 1\\nH           0.564523    0.534352    0.291524 1\\nH           0.446639    0.650520    0.562595 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\nO           0.516309    0.522667    0.527334 1\\nH           0.564523    0.534352    0.291524 1\\nH           0.446639    0.650520    0.562595 1\\nO           0.983691    0.477333    0.027334 1\\nH           0.935477    0.465648   -0.208476 1\\nH           1.053361    0.349480    0.062595 1\\n#END\\n\\n\",\"cif\");\n\tviewer_16009884989238489.animate({\"loop\": \"forward\", \"interval\": 1000});\n\tviewer_16009884989238489.addUnitCell();\n\tviewer_16009884989238489.setStyle({\"model\": 0},{\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n\tviewer_16009884989238489.zoomTo();\nviewer_16009884989238489.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_16009884989238489\"  style=\"position: relative; width: 400px; height: 300px\">\n",
       "        <p id=\"3dmolwarning_16009884989238489\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "      resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n",
       "}\n",
       "\n",
       "var viewer_16009884989238489 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_16009884989238489\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_16009884989238489 = $3Dmol.createViewer($(\"#3dmolviewer_16009884989238489\"),{backgroundColor:\"white\"});\n",
       "\tviewer_16009884989238489.addModelsAsFrames(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\nO           0.516309    0.522667    0.527334 1\\nH           0.564523    0.534352    0.291524 1\\nH           0.446639    0.650520    0.562595 1\\n#END\\n\\n#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'P1'\\n_symmetry_Int_Tables_number                    1\\n_symmetry_cell_setting                 triclinic\\n_cell_length_a            7.043833\\n_cell_length_b            6.448881\\n_cell_length_c            3.835249\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.483691    0.022667    0.972666 1\\nH           0.435477    0.034352    1.208476 1\\nH           0.553361    0.150520    0.937405 1\\nO           0.016309    0.977333    0.472666 1\\nH           0.064523    0.965648    0.708476 1\\nH          -0.053361    0.849480    0.437405 1\\nO           0.516309    0.522667    0.527334 1\\nH           0.564523    0.534352    0.291524 1\\nH           0.446639    0.650520    0.562595 1\\nO           0.983691    0.477333    0.027334 1\\nH           0.935477    0.465648   -0.208476 1\\nH           1.053361    0.349480    0.062595 1\\n#END\\n\\n\",\"cif\");\n",
       "\tviewer_16009884989238489.animate({\"loop\": \"forward\", \"interval\": 1000});\n",
       "\tviewer_16009884989238489.addUnitCell();\n",
       "\tviewer_16009884989238489.setStyle({\"model\": 0},{\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n",
       "\tviewer_16009884989238489.zoomTo();\n",
       "viewer_16009884989238489.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<py3Dmol.view at 0x7ff60514f550>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# It is also fun to check how the structure is generated from a simple animation \n",
    "h2o.show(size=(400, 300), animation=True, interval=1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.2 Crystal with molecules at the special Wyckoff positions\n",
    "\n",
    "In addition to the general `Wyckoff positions` (WP), there are also special WPs which have the `site symmetries` more than the identify operation. If the `molecular symmetry` is compatible with the site symmetry, the molecules can also take the special WPs. In that event, the molecules have less degree of freedom and they can only rotate in a limited range. `PyXtal` takes care of this when dealing the structural manipulation.\n",
    "\n",
    "Below is an example to show the water molecules occupy the 4a site in space group Cmc21(36)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_16009884990099761\"  style=\"position: relative; width: 600px; height: 300px\">\n        <p id=\"3dmolwarning_16009884990099761\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n      resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n}\n\nvar viewer_16009884990099761 = null;\nvar warn = document.getElementById(\"3dmolwarning_16009884990099761\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_16009884990099761 = $3Dmol.createViewer($(\"#3dmolviewer_16009884990099761\"),{backgroundColor:\"white\"});\n\tviewer_16009884990099761.addModel(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'Cmc21'\\n_symmetry_Int_Tables_number                   36\\n_symmetry_cell_setting              orthorhombic\\n_cell_length_a            4.961203\\n_cell_length_b            4.829849\\n_cell_length_c            7.270534\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n2 '-x, -y, z+1/2'\\n3 'x, -y, z+1/2'\\n4 '-x, y, z'\\n5 'x+1/2, y+1/2, z'\\n6 '-x+1/2, -y+1/2, z+1/2'\\n7 'x+1/2, -y+1/2, z+1/2'\\n8 '-x+1/2, y+1/2, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.000000    0.237357    0.147610 1\\nH          -0.153888    0.345969    0.108497 1\\nH           0.153888    0.345969    0.108497 1\\n#END\\n\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n\tviewer_16009884990099761.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n\tviewer_16009884990099761.addUnitCell();\n\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 4.778680440242766e-08, \"y\": 1.4961173170684396, \"z\": 0.8836240704139362}, \"end\": {\"x\": -1.9999999522131957, \"y\": 1.4961173170684396, \"z\": 0.8836240704139362}});\n\tviewer_16009884990099761.addArrow({\"start\": {\"x\": -4.778680377330128e-08, \"y\": 3.3337318565494436, \"z\": 4.518891294999026}, \"end\": {\"x\": -2.000000047786804, \"y\": 3.3337318565494436, \"z\": 4.518891294999026}});\n\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 2.480601747467532, \"y\": 3.911041903877381, \"z\": 0.8836240704139362}, \"end\": {\"x\": 0.4806017474675319, \"y\": 3.911041903877381, \"z\": 0.8836240704139362}});\n\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 2.480601651893924, \"y\": 0.9188072697405021, \"z\": 4.518891294999026}, \"end\": {\"x\": 0.4806016518939238, \"y\": 0.9188072697405021, \"z\": 4.518891294999026}});\n\tviewer_16009884990099761.replicateUnitCell(1,1,1);\n\tviewer_16009884990099761.zoomTo();\nviewer_16009884990099761.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_16009884990099761\"  style=\"position: relative; width: 600px; height: 300px\">\n",
       "        <p id=\"3dmolwarning_16009884990099761\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "      resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n",
       "}\n",
       "\n",
       "var viewer_16009884990099761 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_16009884990099761\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_16009884990099761 = $3Dmol.createViewer($(\"#3dmolviewer_16009884990099761\"),{backgroundColor:\"white\"});\n",
       "\tviewer_16009884990099761.addModel(\"#############################################################\\n#             ______       _    _          _   \\t            #\\n#            (_____ \\\\     \\\\ \\\\  / /        | |               #\\n#             _____) )   _ \\\\ \\\\/ / |_  ____| |  \\t            #\\n#            |  ____/ | | | )  (|  _)/ _  | | \\t            #\\n#            | |    | |_| |/ /\\\\ \\\\ |_( (_| | |___            #\\n#            |_|     \\\\__  /_/  \\\\_\\\\___)__|_|_____)           #\\n#                   (____/                                  #\\n#---------------------(version    0.0.9)--------------------#\\n#       A Python package for random crystal generation      #\\n#       url: https://github.com/qzhu2017/pyxtal             #\\n#       @Zhu's group at University of Nevada Las Vegas      #\\n#############################################################\\ndata_from_pyxtal\\n\\n_symmetry_space_group_name_H-M 'Cmc21'\\n_symmetry_Int_Tables_number                   36\\n_symmetry_cell_setting              orthorhombic\\n_cell_length_a            4.961203\\n_cell_length_b            4.829849\\n_cell_length_c            7.270534\\n_cell_angle_alpha        90.000000\\n_cell_angle_beta         90.000000\\n_cell_angle_gamma        90.000000\\n\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n1 'x, y, z'\\n2 '-x, -y, z+1/2'\\n3 'x, -y, z+1/2'\\n4 '-x, y, z'\\n5 'x+1/2, y+1/2, z'\\n6 '-x+1/2, -y+1/2, z+1/2'\\n7 'x+1/2, -y+1/2, z+1/2'\\n8 '-x+1/2, y+1/2, z'\\n\\nloop_\\n _atom_site_label\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\nO           0.000000    0.237357    0.147610 1\\nH          -0.153888    0.345969    0.108497 1\\nH           0.153888    0.345969    0.108497 1\\n#END\\n\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n",
       "\tviewer_16009884990099761.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n",
       "\tviewer_16009884990099761.addUnitCell();\n",
       "\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 4.778680440242766e-08, \"y\": 1.4961173170684396, \"z\": 0.8836240704139362}, \"end\": {\"x\": -1.9999999522131957, \"y\": 1.4961173170684396, \"z\": 0.8836240704139362}});\n",
       "\tviewer_16009884990099761.addArrow({\"start\": {\"x\": -4.778680377330128e-08, \"y\": 3.3337318565494436, \"z\": 4.518891294999026}, \"end\": {\"x\": -2.000000047786804, \"y\": 3.3337318565494436, \"z\": 4.518891294999026}});\n",
       "\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 2.480601747467532, \"y\": 3.911041903877381, \"z\": 0.8836240704139362}, \"end\": {\"x\": 0.4806017474675319, \"y\": 3.911041903877381, \"z\": 0.8836240704139362}});\n",
       "\tviewer_16009884990099761.addArrow({\"start\": {\"x\": 2.480601651893924, \"y\": 0.9188072697405021, \"z\": 4.518891294999026}, \"end\": {\"x\": 0.4806016518939238, \"y\": 0.9188072697405021, \"z\": 4.518891294999026}});\n",
       "\tviewer_16009884990099761.replicateUnitCell(1,1,1);\n",
       "\tviewer_16009884990099761.zoomTo();\n",
       "viewer_16009884990099761.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<py3Dmol.view at 0x7ff5ffdc8f50>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h2o_36 = molecular_crystal(36, ['H2O'], [2])\n",
    "ax = h2o_36.mol_sites[0].orientation.axis\n",
    "h2o_36.show(axis=ax*2) #show the rotational axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f0809fe7382b425289a1879a27da333b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=0, description='id:', max=3), Output()), _dom_classes=('widget-interact'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Below is a script to show how the molecules rotate around the allowed axis\n",
    "strucs = []\n",
    "for angle in [90, 180, 270, 360]:\n",
    "    struc = h2o_36.copy()\n",
    "    struc.mol_sites[0].rotate(axis=ax, angle=angle)\n",
    "    strucs.append(struc)\n",
    "    \n",
    "from pyxtal.viz import display_mol_crystals\n",
    "display_mol_crystals(strucs, axis=2*ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.3 2D and 1D Crystals \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------Random Molecular Crystal------\n",
      "Dimension: 1\n",
      "Group: p6/mmc\n",
      "Volume factor: 1.1\n",
      "hexagonal lattice:   5.4601   5.4601  10.1214  90.0000  90.0000 120.0000\n",
      "Wyckoff sites:\n",
      "\tH2O1 @ [0.1696 0.3392 0.2500]  WP:  6d, Site symmetry m m2 . ==> Euler: 53.486 22.802 -133.633\n"
     ]
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_16009884994495091\"  style=\"position: relative; width: 600px; height: 300px\">\n        <p id=\"3dmolwarning_16009884994495091\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n      resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n}\n\nvar viewer_16009884994495091 = null;\nvar warn = document.getElementById(\"3dmolwarning_16009884994495091\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_16009884994495091 = $3Dmol.createViewer($(\"#3dmolviewer_16009884994495091\"),{backgroundColor:\"white\"});\n\tviewer_16009884994495091.addModel(\"# generated using pymatgen\\ndata_H2O\\n_symmetry_space_group_name_H-M   'P 1'\\n_cell_length_a   20.46012545\\n_cell_length_b   20.46012545\\n_cell_length_c   10.12144043\\n_cell_angle_alpha   90.00000000\\n_cell_angle_beta   90.00000000\\n_cell_angle_gamma   120.00000000\\n_symmetry_Int_Tables_number   1\\n_chemical_formula_structural   H2O\\n_chemical_formula_sum   'H12 O6'\\n_cell_volume   3669.35338668\\n_cell_formula_units_Z   6\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n  1  'x, y, z'\\nloop_\\n _atom_site_type_symbol\\n _atom_site_label\\n _atom_site_symmetry_multiplicity\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\n  H  H0  1  0.63842011  0.54370688  0.17456909  1\\n  H  H1  1  0.63842012  0.54370691  0.32543088  1\\n  H  H2  1  0.45777187  0.36305865  0.17456909  1\\n  H  H3  1  0.45777185  0.36305864  0.32543088  1\\n  H  H4  1  0.63842011  0.36305865  0.17456909  1\\n  H  H5  1  0.63842012  0.36305864  0.32543088  1\\n  H  H6  1  0.51798795  0.30284257  0.67456909  1\\n  H  H7  1  0.51798794  0.30284255  0.82543088  1\\n  H  H8  1  0.69863619  0.48349081  0.67456909  1\\n  H  H9  1  0.69863621  0.48349082  0.82543088  1\\n  H  H10  1  0.51798795  0.48349081  0.67456909  1\\n  H  H11  1  0.51798794  0.48349082  0.82543088  1\\n  O  O12  1  0.62158217  0.51003100  0.25000002  1\\n  O  O13  1  0.49144776  0.37989659  0.25000002  1\\n  O  O14  1  0.62158217  0.37989659  0.25000002  1\\n  O  O15  1  0.53482590  0.33651846  0.75000002  1\\n  O  O16  1  0.66496030  0.46665286  0.75000002  1\\n  O  O17  1  0.53482590  0.46665286  0.75000002  1\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n\tviewer_16009884994495091.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n\tviewer_16009884994495091.addUnitCell();\n\tviewer_16009884994495091.replicateUnitCell(1,1,3);\n\tviewer_16009884994495091.zoomTo();\nviewer_16009884994495091.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_16009884994495091\"  style=\"position: relative; width: 600px; height: 300px\">\n",
       "        <p id=\"3dmolwarning_16009884994495091\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "      resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n",
       "}\n",
       "\n",
       "var viewer_16009884994495091 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_16009884994495091\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_16009884994495091 = $3Dmol.createViewer($(\"#3dmolviewer_16009884994495091\"),{backgroundColor:\"white\"});\n",
       "\tviewer_16009884994495091.addModel(\"# generated using pymatgen\\ndata_H2O\\n_symmetry_space_group_name_H-M   'P 1'\\n_cell_length_a   20.46012545\\n_cell_length_b   20.46012545\\n_cell_length_c   10.12144043\\n_cell_angle_alpha   90.00000000\\n_cell_angle_beta   90.00000000\\n_cell_angle_gamma   120.00000000\\n_symmetry_Int_Tables_number   1\\n_chemical_formula_structural   H2O\\n_chemical_formula_sum   'H12 O6'\\n_cell_volume   3669.35338668\\n_cell_formula_units_Z   6\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n  1  'x, y, z'\\nloop_\\n _atom_site_type_symbol\\n _atom_site_label\\n _atom_site_symmetry_multiplicity\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\n  H  H0  1  0.63842011  0.54370688  0.17456909  1\\n  H  H1  1  0.63842012  0.54370691  0.32543088  1\\n  H  H2  1  0.45777187  0.36305865  0.17456909  1\\n  H  H3  1  0.45777185  0.36305864  0.32543088  1\\n  H  H4  1  0.63842011  0.36305865  0.17456909  1\\n  H  H5  1  0.63842012  0.36305864  0.32543088  1\\n  H  H6  1  0.51798795  0.30284257  0.67456909  1\\n  H  H7  1  0.51798794  0.30284255  0.82543088  1\\n  H  H8  1  0.69863619  0.48349081  0.67456909  1\\n  H  H9  1  0.69863621  0.48349082  0.82543088  1\\n  H  H10  1  0.51798795  0.48349081  0.67456909  1\\n  H  H11  1  0.51798794  0.48349082  0.82543088  1\\n  O  O12  1  0.62158217  0.51003100  0.25000002  1\\n  O  O13  1  0.49144776  0.37989659  0.25000002  1\\n  O  O14  1  0.62158217  0.37989659  0.25000002  1\\n  O  O15  1  0.53482590  0.33651846  0.75000002  1\\n  O  O16  1  0.66496030  0.46665286  0.75000002  1\\n  O  O17  1  0.53482590  0.46665286  0.75000002  1\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n",
       "\tviewer_16009884994495091.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n",
       "\tviewer_16009884994495091.addUnitCell();\n",
       "\tviewer_16009884994495091.replicateUnitCell(1,1,3);\n",
       "\tviewer_16009884994495091.zoomTo();\n",
       "viewer_16009884994495091.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<py3Dmol.view at 0x7ff60514f750>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyxtal.molecular_crystal import molecular_crystal_1D\n",
    "\n",
    "h2o_1D = molecular_crystal_1D(75, ['H2O'], [6])\n",
    "print(h2o_1D)\n",
    "h2o_1D.show(supercell=(1,1,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------Random Molecular Crystal------\n",
      "Dimension: 2\n",
      "Group: pba2\n",
      "Volume factor: 1.1\n",
      "orthorhombic lattice:  10.8682   5.3433   3.0000  90.0000  90.0000  90.0000\n",
      "Wyckoff sites:\n",
      "\tH2O1 @ [0.0269 0.6903 0.5000]  WP:  4c, Site symmetry 1 ==> Euler: 14.975 -7.771 20.786\n"
     ]
    },
    {
     "data": {
      "application/3dmoljs_load.v0": "<div id=\"3dmolviewer_16009884995574799\"  style=\"position: relative; width: 600px; height: 300px\">\n        <p id=\"3dmolwarning_16009884995574799\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n        </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n  return new Promise((resolve, reject) => {\n    var tag = document.createElement('script');\n    tag.src = uri;\n    tag.async = true;\n    tag.onload = () => {\n      resolve();\n    };\n  var firstScriptTag = document.getElementsByTagName('script')[0];\n  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n}\n\nvar viewer_16009884995574799 = null;\nvar warn = document.getElementById(\"3dmolwarning_16009884995574799\");\nif(warn) {\n    warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_16009884995574799 = $3Dmol.createViewer($(\"#3dmolviewer_16009884995574799\"),{backgroundColor:\"white\"});\n\tviewer_16009884995574799.addModel(\"# generated using pymatgen\\ndata_H2O\\n_symmetry_space_group_name_H-M   'P 1'\\n_cell_length_a   10.86822484\\n_cell_length_b   5.34326937\\n_cell_length_c   18.00000000\\n_cell_angle_alpha   90.00000000\\n_cell_angle_beta   90.00000000\\n_cell_angle_gamma   90.00000000\\n_symmetry_Int_Tables_number   1\\n_chemical_formula_structural   H2O\\n_chemical_formula_sum   'H8 O4'\\n_cell_volume   1045.29335211\\n_cell_formula_units_Z   4\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n  1  'x, y, z'\\nloop_\\n _atom_site_type_symbol\\n _atom_site_label\\n _atom_site_symmetry_multiplicity\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\n  H  H0  1  0.03191827  0.86171587  0.50822160  1\\n  H  H1  1  0.05745956  0.65028114  0.45327649  1\\n  H  H2  1  -0.03191827  -0.86171587  0.50822160  1\\n  H  H3  1  -0.05745956  -0.65028114  0.45327649  1\\n  H  H4  1  0.53191827  -0.36171587  0.50822160  1\\n  H  H5  1  0.55745956  -0.15028114  0.45327649  1\\n  H  H6  1  0.46808173  1.36171587  0.50822160  1\\n  H  H7  1  0.44254044  1.15028114  0.45327649  1\\n  O  O8  1  0.02460702  0.68203681  0.50242556  1\\n  O  O9  1  -0.02460702  -0.68203681  0.50242556  1\\n  O  O10  1  0.52460702  -0.18203681  0.50242556  1\\n  O  O11  1  0.47539298  1.18203681  0.50242556  1\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n\tviewer_16009884995574799.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n\tviewer_16009884995574799.addUnitCell();\n\tviewer_16009884995574799.replicateUnitCell(2,2,1);\n\tviewer_16009884995574799.zoomTo();\nviewer_16009884995574799.render();\n});\n</script>",
      "text/html": [
       "<div id=\"3dmolviewer_16009884995574799\"  style=\"position: relative; width: 600px; height: 300px\">\n",
       "        <p id=\"3dmolwarning_16009884995574799\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason).  You need to install the 3dmol extension: <br>\n",
       "        <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n",
       "        </div>\n",
       "<script>\n",
       "\n",
       "var loadScriptAsync = function(uri){\n",
       "  return new Promise((resolve, reject) => {\n",
       "    var tag = document.createElement('script');\n",
       "    tag.src = uri;\n",
       "    tag.async = true;\n",
       "    tag.onload = () => {\n",
       "      resolve();\n",
       "    };\n",
       "  var firstScriptTag = document.getElementsByTagName('script')[0];\n",
       "  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n",
       "});\n",
       "};\n",
       "\n",
       "if(typeof $3Dmolpromise === 'undefined') {\n",
       "$3Dmolpromise = null;\n",
       "  $3Dmolpromise = loadScriptAsync('https://3dmol.csb.pitt.edu/build/3Dmol.js');\n",
       "}\n",
       "\n",
       "var viewer_16009884995574799 = null;\n",
       "var warn = document.getElementById(\"3dmolwarning_16009884995574799\");\n",
       "if(warn) {\n",
       "    warn.parentNode.removeChild(warn);\n",
       "}\n",
       "$3Dmolpromise.then(function() {\n",
       "viewer_16009884995574799 = $3Dmol.createViewer($(\"#3dmolviewer_16009884995574799\"),{backgroundColor:\"white\"});\n",
       "\tviewer_16009884995574799.addModel(\"# generated using pymatgen\\ndata_H2O\\n_symmetry_space_group_name_H-M   'P 1'\\n_cell_length_a   10.86822484\\n_cell_length_b   5.34326937\\n_cell_length_c   18.00000000\\n_cell_angle_alpha   90.00000000\\n_cell_angle_beta   90.00000000\\n_cell_angle_gamma   90.00000000\\n_symmetry_Int_Tables_number   1\\n_chemical_formula_structural   H2O\\n_chemical_formula_sum   'H8 O4'\\n_cell_volume   1045.29335211\\n_cell_formula_units_Z   4\\nloop_\\n _symmetry_equiv_pos_site_id\\n _symmetry_equiv_pos_as_xyz\\n  1  'x, y, z'\\nloop_\\n _atom_site_type_symbol\\n _atom_site_label\\n _atom_site_symmetry_multiplicity\\n _atom_site_fract_x\\n _atom_site_fract_y\\n _atom_site_fract_z\\n _atom_site_occupancy\\n  H  H0  1  0.03191827  0.86171587  0.50822160  1\\n  H  H1  1  0.05745956  0.65028114  0.45327649  1\\n  H  H2  1  -0.03191827  -0.86171587  0.50822160  1\\n  H  H3  1  -0.05745956  -0.65028114  0.45327649  1\\n  H  H4  1  0.53191827  -0.36171587  0.50822160  1\\n  H  H5  1  0.55745956  -0.15028114  0.45327649  1\\n  H  H6  1  0.46808173  1.36171587  0.50822160  1\\n  H  H7  1  0.44254044  1.15028114  0.45327649  1\\n  O  O8  1  0.02460702  0.68203681  0.50242556  1\\n  O  O9  1  -0.02460702  -0.68203681  0.50242556  1\\n  O  O10  1  0.52460702  -0.18203681  0.50242556  1\\n  O  O11  1  0.47539298  1.18203681  0.50242556  1\\n\",\"cif\",{\"doAssembly\": true, \"duplicateAssemblyAtoms\": true, \"normalizeAssembly\": true});\n",
       "\tviewer_16009884995574799.setStyle({\"stick\": {\"colorscheme\": \"greenCarbon\"}});\n",
       "\tviewer_16009884995574799.addUnitCell();\n",
       "\tviewer_16009884995574799.replicateUnitCell(2,2,1);\n",
       "\tviewer_16009884995574799.zoomTo();\n",
       "viewer_16009884995574799.render();\n",
       "});\n",
       "</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<py3Dmol.view at 0x7ff60487dfd0>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyxtal.molecular_crystal import molecular_crystal_2D\n",
    "\n",
    "h2o_2D = molecular_crystal_2D(25, ['H2O'], [4], thickness=0)\n",
    "print(h2o_2D)\n",
    "h2o_2D.show(supercell=(2,2,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "@webio": {
   "lastCommId": null,
   "lastKernelId": null
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
